import {defineStore} from 'pinia'
import {
    RECEIVE_DETAIL,
    RECEIVE_LIST,
    RECEIVE_SAVE,
    request_post_receive_detail,
    request_post_user_receive_list,
    request_post_user_receive_save,
} from '../service/receive'
import {reactive} from 'vue'

export default defineStore('useUserReceive', () => {
    let userReceiveListData = reactive({
        objects: [],
        pageNo: 0,
        pageSize: 0,
        total: 0,
        totalPage: 0
    })
    // 优惠券领取详情
    const userReceiveDetial = async (receiveDetail: RECEIVE_DETAIL) => {
        const res = await request_post_receive_detail(receiveDetail)
        return res
    }

    //用户优惠券列表
    const userReceiveList = async (receiveList: RECEIVE_LIST) => {
        const res = await request_post_user_receive_list(receiveList)
        userReceiveListData.objects = res.data?.objects
        userReceiveListData.pageNo = res.data?.pageNo
        userReceiveListData.pageSize = res.data?.pageSize
        userReceiveListData.total = res.data?.total
        userReceiveListData.totalPage = res.data?.totalPage
    }

    // 用户领取优惠券
    const userReceiveSave = async (receiveSave: Partial<RECEIVE_SAVE>) => {
        const res = await request_post_user_receive_save(receiveSave)
        return res
    }

    return {
        userReceiveDetial,
        userReceiveList,
        userReceiveSave,
        userReceiveListData,
    }
})